package com.itbaizhan.login.aop;

import com.itbaizhan.common.vo.LivegoodsResult;
import com.itbaizhan.login.mapper.LoginMapper;
import com.itbaizhan.pojo.LoginLog;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect //当前为切面
public class LoginAOP {

    @Autowired
    private LoginMapper loginMapper;

    @AfterReturning(pointcut = "execution(* com.itbaizhan.login.service.impl.LoginServiceImpl.login(String,String)) && args(username,password)"
    ,returning = "result")
    public void addLoginLog(String username, String password, LivegoodsResult result){
        LoginLog loginLog = new LoginLog();
        loginLog.setPhone(username);
        loginLog.setLoginType("验证码");
        loginLog.setLoginTime(new Date());
        if (result.getStatus()==200){
            loginLog.setLoginResult("登录成功");
        }else{
            loginLog.setLoginResult("登陆失败");
        }
        loginMapper.insertLoginLog(loginLog);
    }

}
